var assert = require('assert');
var should = require('should');
var util = require('util');
var zlib = require('zlib');
var _ = require('lodash');
var harryHandler = require('../../../app/servers/pvp/handler/harryHandler');
var config = require('../../config');
var atkData = require('../../../app/libs/war/atkData');
var battleData = require('../../../app/libs/war/battleData');
var battleRecordModel = require('../../../app/models/battleRecordModel');
var configUtil = require('../../../app/util/configUtil');
var analyze = require('kc-analyze');

suite('统计数据', function () {
    test('初始化', function (done) {
        var analyze_config = configUtil.load('analyze');
        var game_config = configUtil.load('game');
        analyze.initialize({
            host: analyze_config.host,
            server_id: game_config.server_id
        });
        done();
    });
});

suite('测试battle.harryHandler', function () {
    var battle_record_model;
    setup(function (done) {
        atkData.getData(config.role_id, function (err, atk_data) {
            battleData.getData(config.role_id, function (err, def_data) {
                battleRecordModel.addRecord(config.role_id, config.role_id, atk_data, def_data, function (err, model) {
                    battle_record_model = model;
                    done();
                });
            });
        });
    });

    suite('battle.harryHandler.exit', function () {
        // test('离开战斗成功1', function (done) {
        //     var msg = {};
        //     msg.record_id = battle_record_model.getRecordId();
        //     msg.destroy_build_list = [{
        //         build_type: 10000
        //     }, {
        //         build_type: 12345
        //     }];
        //     msg.economy_build_list = [];

        //     var session = {};
        //     session.get = function (key) {
        //         var map = {};
        //         map.sign = '111111';
        //         return map[key];
        //     };
        //     session.uid = config.role_id;

        //     var harry_handler = new harryHandler();
        //     harry_handler.exit(msg, session, function (err, res) {
        //         // res.code.should.eql(600);
        //         done();
        //     });
        // });

        test('离开战斗成功2', function (done) {
            var msg = {};
            msg.record_id = 10000;
            msg.key = '123';
            msg.verify = 'c99fbea5598955bed505af10a57b3a38';
            msg.damage_build_list = [{
                build_type: 10000
            }, {
                build_type: 12345
            }];

            var session = {};
            session.get = function (key) {
                var map = {};
                map.sign = '111111';
                return map[key];
            };
            session.uid = config.role_id;

            var harry_handler = new harryHandler();
            harry_handler.exit(msg, session, function (err, res) {
                // res.code.should.eql(200);
                done();
            });
        });

        // test('离开战斗成功3', function (done) {
        //     var msg = {};

        //     var session = {};
        //     // session.uid = config.role_id;

        //     session.uid = 10001;
        //     msg.record_id = 10001;
        //     msg.damage_build_list = [{
        //         "hp": 0,
        //         "build_id": 11201
        //     }, {
        //         "hp": 0,
        //         "build_id": 21201
        //     }];
        //     var harry_handler = new harryHandler();
        //     harry_handler.exit(msg, session, function (err, res) {
        //         // res.code.should.eql(200);
        //         // console.log('res:', res);
        //         done();
        //     });
        // });
    });
});
